package com.chapter03;

import com.bdqn.util.JDBCUtils;

import java.sql.*;

public class Test04_Select {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Connection connection = JDBCUtils.getConnection();
//        Statement statement = connection.createStatement();
//        String sql = "SELECT GradeId,GradeName FROM grade;";
//        ResultSet resultSet = statement.executeQuery(sql);

        String sql = "SELECT GradeId,GradeName FROM grade;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();

        System.out.println("年级编号\t年级名称");
        while (resultSet.next()) {
//            int gradeId1 = resultSet.getInt(1);
            int gradeId2 = resultSet.getInt("GradeId");
//            System.out.print(gradeId1 + "--" + gradeId2 + "--");

//            String gradeName1 = resultSet.getString(2);
            String gradeName2 = resultSet.getString("GradeName");
//            System.out.println(gradeName1 + "--" + gradeName2);
            System.out.println(gradeId2 + "\t" + gradeName2);
        }

        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
